<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<%include("/common/include.html"){}%>
	</head>
	<body class="easyui-layout">
	<div data-options="region:'north',split: true,title:'快速查询'" style="height:120px;padding:10px;">
	<!-- <input id="orgid"  type="hidden" value="${orgid!}"> -->
		<form id="zdMonthStatisticFrom"  action="${cxt!}/zdMonthStastic/excel">
		
			<div style="margin-bottom: 10px;float:left;margin-right: 10px;">
					<label class="label-top" style="width: 100%; display: block;">日期</label>
					<input  id="zdMonth_datebox" name="bussdate" value='${date()}' class="easyui-datebox theme-textbox-radius"style="height: 32px; width: 212px; text-align: center" />
			</div>
			
			<div>
				<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'"  style="width:212px;height:32px;float:left;margin-top: 16px;margin-right: 10px;"  onclick="searchBus()">搜索</a>
			</div>
			<div style="margin-bottom: 10px;float:left;margin-top: 16px;margin-right: 10px;">
				<a href="#" onclick='zdMonthInfo_xls()' class="easyui-linkbutton" data-options="iconCls:'icon-pageexcel'" style="width:212px">导出</a>
			</div>
		</form>
		</div>
		<div data-options="region:'center'" style="overflow-x:hidden;">
		<table class="easyui-datagrid" id ="zdMonthStasticInfo" style="width:100%;height:auto;"></table>
		</div>
		
		<script>
		
		
		var $form = $('#zdMonthStatisticFrom');
		function zdMonthStastic(){
			$('#zdMonthStasticInfo').datagrid({
				cls: "theme-datagrid",
				singleSelect: true,
				rownumbers: true, //显示序号
				fitColumns:true,
				pagination: false,
				url: "zdMonthStastic/getList",
				queryParams: sy.serializeObject($form),
			    method: 'post',
			    collapsible:true,
			    columns:[[
							{field:'ids',title:'ids',width:10,align:'center',hidden:true},
							{field:'organname',title:'机构',width:10,align:'center'},
							{field:'zcgd',title:'注册登记',width:10,align:'center'},
							{field:'zygd',title:'转移登记',width:10, align:'center'},
							{field:'bggd',title:'变更登记',width:10,align:'center'},
							{field:'bhpgd',title:'补换号牌',width:10, align:'center'},
							{field:'bzjgd',title:'补换证件',width:10, align:'center'},
							{field:'zxgd',title:'注销登记',width:10, align:'center'}
							]],
							 onLoadSuccess:function(data){
									var rows = $('#zdMonthStasticInfo').datagrid('getRows');
									if(rows.length > 0){
										$('#zdMonthStasticInfo').datagrid('insertRow', {
											index: 0,
											row: {
													organname: '合计',
													zcgd:compute_GXC('zcgd'),
													zygd:compute_GXC('zygd'),
													bggd:compute_GXC('bggd'),
													bhpgd:compute_GXC('bhpgd'),
													bzjgd:compute_GXC('bzjgd'),
													zxgd:compute_GXC('zxgd')
												
											}
							             });
								
								
									} 
								}
			})
			
		}
		
		
		$(document).ready(function () {
			dateFormatter();
			zdMonthStastic();
		});
		
		
		function searchBus(){
			 zdMonthStastic();
		}
		//指定列求和
		function compute_GXC(colName) {
		     var rows = $('#zdMonthStasticInfo').datagrid('getRows');
		     var total = 0;
		     for (var i = 0; i < rows.length; i++) {
		    	 if(typeof(rows[i][colName]) != 'undefined'){
		    		 total += parseFloat(rows[i][colName]);
		    	 }
		     }
		     if(total > 0){
		    	 return total;
		     }else{
		    	 return 0;
		     }
		}
		function zdMonthInfo_xls(){
			$form.submit();
		}
		
		function  dateFormatter(){
			$('#zdMonth_datebox').datebox({
			       //显示日趋选择对象后再触发弹出月份层的事件，初始化时没有生成月份层
			       onShowPanel: function () {
			          //触发click事件弹出月份层
			          span.trigger('click'); 
			          if (!tds)
			            //延时触发获取月份对象，因为上面的事件触发和对象生成有时间间隔
			            setTimeout(function() { 
			                tds = p.find('div.calendar-menu-month-inner td');
			                tds.click(function(e) {
			                   //禁止冒泡执行easyui给月份绑定的事件
			                   e.stopPropagation(); 
			                   //得到年份
			                   var year = /\d{4}/.exec(span.html())[0] ,
			                   //月份
			                   //之前是这样的month = parseInt($(this).attr('abbr'), 10) + 1; 
			                   month = parseInt($(this).attr('abbr'), 10);  

						         //隐藏日期对象                     
						         $('#zdMonth_datebox').datebox('hidePanel').datebox('setValue', year + '-' + month); 
			                 });
			             }, 0);
			        },
			            //配置parser，返回选择的日期
			            parser: function (s) {
			                if (!s) return new Date();
			                var arr = s.split('-');
			                return new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, 1);
			            },
			            //配置formatter，只返回年月 之前是这样的d.getFullYear() + '-' +(d.getMonth()); 
			            formatter: function (d) { 
			                var currentMonth = (d.getMonth()+1);
			                var currentMonthStr = currentMonth < 10 ? ('0' + currentMonth) : (currentMonth + '');
			                return d.getFullYear() + '-' + currentMonthStr; 
			            }
			        });

			        //日期选择对象
			        var p = $('#zdMonth_datebox').datebox('panel'), 
			        //日期选择对象中月份
			        tds = false, 
			        //显示月份层的触发控件
			        span = p.find('span.calendar-text'); 
			        var curr_time = new Date();

			        //设置前当月
			        $("#zdMonth_datebox").datebox("setValue", myformatter(curr_time));
		    
		 
		}
		
		//格式化日期
		function myformatter(date) {
		    //获取年份
		    var y = date.getFullYear();
		    //获取月份
		    var m = date.getMonth() + 1;
		    return y + '-' + m;
		}


		
		</script>
	</body>
</html>
